<template>
  <div
    class="buttonsContainer"
    :style="{
      paddingBottom: tempData.paddingBottom + 'px',
      paddingLeft: tempData.paddingTwice + 'px',
      paddingRight: tempData.paddingTwice + 'px',
      paddingTop: tempData.paddingTop + 'px',
      boxSizing: 'border-box',
    }"
  >
    <div
      class="btnsContents3"
      ref="divDomBtn"
      :style="{
        borderTopLeftRadius: tempData.radiusNumTop + 'px',
        borderTopRightRadius: tempData.radiusNumTop + 'px',
        borderBottomLeftRadius: tempData.radiusNumBottom + 'px',
        borderBottomRightRadius: tempData.radiusNumBottom + 'px',
      }"
      v-if="tempData.styleType == 1"
    >
      <div
        class="buttons"
        v-for="(item, index) in btnList"
        :key="index"
        :style="
          tempData.showType == 1
            ? { backgroundColor: tempData.boxBg }
            : { backgroundImage: 'url(' + tempData.bgImage + ')', backgroundSize: '100% 100%' }
        "
        v-show="item.status == 0"
      >
        <div class="iconBox" style="display: flex; justify-content: center; align-items: center">
          <img style="width: 35px; height: 35px" :src="item.img" alt="" />
          <p
            style="font-size: 15px; margin-left: 6px; text-align: center"
            :style="{ color: tempData.fontColor }"
            class="texts"
            >{{ item.name }}</p
          >
        </div>
        <icon-right style="font-size: 24px" />
      </div>
    </div>
    <div
      class="btnsContents4"
      ref="divDomBtn"
      :style="
        tempData.showType == 1
          ? {
              borderTopLeftRadius: tempData.radiusNumTop + 'px',
              borderTopRightRadius: tempData.radiusNumTop + 'px',
              borderBottomLeftRadius: tempData.radiusNumBottom + 'px',
              borderBottomRightRadius: tempData.radiusNumBottom + 'px',
              backgroundColor: tempData.boxBg,
            }
          : {
              borderTopLeftRadius: tempData.radiusNumTop + 'px',
              borderTopRightRadius: tempData.radiusNumTop + 'px',
              borderBottomLeftRadius: tempData.radiusNumBottom + 'px',
              borderBottomRightRadius: tempData.radiusNumBottom + 'px',
              backgroundImage: 'url(' + tempData.bgImage + ')',
              backgroundSize: '100% 100%',
            }
      "
      v-else-if="tempData.styleType == 2"
    >
      <div class="buttons2" v-for="(item, index) in btnList" :key="index" v-show="item.status == 0">
        <div class="iconBox" style="display: flex; justify-content: center; align-items: center">
          <img style="width: 35px; height: 35px" :src="item.img" alt="" />
          <p
            style="font-size: 15px; margin-left: 6px; text-align: center"
            :style="{ color: tempData.fontColor }"
            class="texts"
            >{{ item.name }}</p
          >
        </div>
        <icon-right style="font-size: 24px" />
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
  import btn2 from '@/assets/didaima/gengduo.png'
  import { watch, ref, onMounted } from 'vue'
  const props = defineProps({
    // 选中的当前组件参数
    compObj: {
      type: Object,
      default: () => {
        return {}
      },
    },
  })
  const divDomBtn: any = ref(null)
  const tempData: any = ref({})
  const btnList: any = ref([])
  const btnWidth = ref('')
  const items = ref()
  watch(
    () => props.compObj,
    (newVal, oldVal) => {
      tempData.value = JSON.parse(JSON.stringify(newVal))
      btnList.value = tempData.value.btnList.slice(0, tempData.value.showNum)
      if (tempData.value.showMore) {
        const newItem = {
          name: '更多功能',
          img: btn2,
          tag: false,
          link: '/pages/home/balance',
          tagBg: '#ff0000',
          status: 0,
          tagColor: '#ffffff',
          showChooseColor1: false,
          showChooseColor2: false,
        }
        // 使用splice方法在第三条数据的位置插入新对象
        btnList.value.splice(tempData.value.showNum + 1, 0, newItem)
      }
      // return a
    },
    { immediate: true, deep: true }
  )
</script>

<style scoped lang="less">
  .buttonsContainer {
    width: 100%;

    .btnsContent {
      background-color: #fff;
      display: flex;
      justify-content: space-between;
      flex-wrap: wrap;
      align-items: center;
      padding: 20px 15px 0px 15px;
      box-sizing: border-box;

      .buttons {
        margin-bottom: 18px;
        position: relative;

        .tags {
          width: auto;
          border-radius: 6px;
          font-size: 10px;
          line-height: 12px;
          padding: 2px 4px;
          box-sizing: border-box;
          text-align: center;
          position: absolute;
          top: 0px;
          right: 10px;
        }

        .items {
          width: 100%;
          display: flex;
          flex-wrap: wrap;
          justify-content: center;

          .texts {
            width: 100%;
            text-align: center;
            color: #303133;
            font-size: 12px;
          }

          img {
            width: 35px;
            height: 35px;
          }
        }
      }
    }
    .btnsContents4 {
      display: flex;
      justify-content: space-between;
      flex-wrap: wrap;
      align-items: center;
      box-sizing: border-box;
      position: relative;
      padding: 0px 20px;
      .lines {
        width: 1px;
        height: 32px;
        background: #e9e9e9;
        position: absolute;
        left: 50%;
        top: 17px;
      }
      .buttons2:last-child {
        border-bottom: none;
      }
      .buttons2 {
        border-bottom: 1px solid #e5e6eb;
        box-sizing: border-box;
        padding: 20px 0px;
        box-sizing: border-box;
        width: 100%;
        display: flex;
        justify-content: space-between;
        align-items: center;
        position: relative;

        .tags {
          width: auto;
          border-radius: 6px;
          font-size: 10px;
          line-height: 12px;
          padding: 2px 4px;
          box-sizing: border-box;
          text-align: center;
          position: absolute;
          top: 0px;
          right: 10px;
        }

        .items {
          width: 100%;
          display: flex;
          flex-wrap: wrap;
          justify-content: center;

          .texts {
            width: 100%;
            text-align: center;
            color: #303133;
            font-size: 12px;
          }

          img {
            width: 35px;
            height: 35px;
          }
        }
      }
    }
    .btnsContents3 {
      display: flex;
      justify-content: space-between;
      flex-wrap: wrap;
      align-items: center;
      box-sizing: border-box;
      position: relative;

      .lines {
        width: 1px;
        height: 32px;
        background: #e9e9e9;
        position: absolute;
        left: 50%;
        top: 17px;
      }
      .buttons:last-child {
        margin-bottom: 0px;
      }
      .buttons {
        padding: 15px 20px;
        margin-bottom: 10px;
        box-sizing: border-box;
        border-radius: 10px;
        background-color: #fff;
        width: 100%;
        display: flex;
        justify-content: space-between;
        align-items: center;
        position: relative;

        .tags {
          width: auto;
          border-radius: 6px;
          font-size: 10px;
          line-height: 12px;
          padding: 2px 4px;
          box-sizing: border-box;
          text-align: center;
          position: absolute;
          top: 0px;
          right: 10px;
        }

        .items {
          width: 100%;
          display: flex;
          flex-wrap: wrap;
          justify-content: center;

          .texts {
            width: 100%;
            text-align: center;
            color: #303133;
            font-size: 12px;
          }

          img {
            width: 35px;
            height: 35px;
          }
        }
      }
    }
  }
</style>
